package com.hehao.java_basic.function;

import java.util.function.Function;
import java.util.stream.Stream;

/**
 * @author Damon
 * @date 2022/08/15/20:58
 */
public class FunctionDemo {
    public static void main(String[] args) {
        //1.匿名内部类方式创建函数方法
        Function<String, Integer> function1 = new Function<String, Integer>() {
            @Override
            public Integer apply(String s) {
                return s.length();
            }
        };
        //2.lambda表达式创建函数方法
        Function<String, Integer> function2 = s -> s.length();
        //2.1 ::方法引用
        Function<String, Integer> function3 = String::length;

        Stream<String> stream = Stream.of("aaa", "bbbbb", "ccccccv");
        Stream<Integer> stream1 = stream.map(function3);
        stream1.forEach(System.out::println);


    }
}
